<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>后台管理</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="asserts/css/dashboard.css" th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">
    <link href="iconfont/iconfont.css" th:href="@{/iconfont/iconfont.css}" rel="stylesheet">

    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        .info {
            float: left;
        }

        .pagination {
            float: right;
        }

        .add {
            float: left;
        }

        .navbar-form {
            float: right;
        }


        img {
            height: 20px;
            width: 20px;
        }

    </style>

</head>

<body>
<!--引入抽取的topbar-->
<!--模板名：会使用thymeleaf的前后缀配置规则进行解析-->
<div th:replace="commons/bar::topbar"></div>

<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/bar::#sidebar(activeUri='emps')"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">

            <h2 class="add"><a class="btn btn-outline-success " href="emp" th:href="@{/emp}">新增</a></h2>

<!--            测试-->
<!--            <h2 class="add"><a class="btn btn-outline-success " href="emp" th:if="${session.loginUser.username}=='root'" th:href="@{/emp}">新增</a></h2>-->


            <form class="navbar-form navbar-right" th:action="@{/search}" method="post">
                <div class="input-group mb-3">
                    <input name="name" type="text" class="form-control " placeholder="请输入要查询的员工姓名">
                    <div class="input-group-append">
                        <button class="btn btn-success" type="submit">
                            <span class="iconfont icon&#45;&#45;search1"></span>
                        </button>
                    </div>
                </div>

            </form>
            <div class="table-responsive">
                <table class="table table-striped table-sm table-bordered">
                    <thead>
                    <tr>
                        <th>员工编号</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>年龄</th>
<!--                        <th>工龄</th>-->
                        <th>电话</th>
                        <th>毕业院校</th>
                        <th>部门</th>
                        <th>职位</th>
                        <th>功能</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="emp:${pageInfo.list}">

                        <td>[[${emp.id}]]</td>
                        <td>[[${emp.name}]]</td>
<!--                        <td>[[${emp.gender}]]</td>-->


                        <td>
                            <div th:switch="${emp.gender}">
                                <option th:case="男" class="text-primary">男</option>
                                <option th:case="女" class="text-danger">女</option>
                                <option th:case="*">其他</option>
                            </div>
                        </td>
                        <!--                        <td>[[${emp.age}]]</td>-->
                        <td>
                            <div th:if="${emp.age}>=35" th:text="${emp.age}" class="text-danger"></div>
                            <div th:if="${emp.age}<35" th:text="${emp.age}"></div>

                        </td>


<!--                                                <td>[[${emp.workAge}]]</td>-->

<!--                        <td>-->
<!--                            <div th:if="${emp.workAge}>=10" th:text="${emp.workAge}" style="color: red"></div>-->
<!--                            <div th:if="${emp.workAge<10 and emp.workAge >= 5}" th:text="${emp.workAge}"-->
<!--                                 style="color: green"></div>-->
<!--                            <div th:if="${emp.workAge<5}" th:text="${emp.workAge}" style="color: blue"></div>-->

<!--                        </td>-->
                        <td>[[${emp.phone}]]</td>
                        <td>[[${emp.address}]]</td>
                        <td>[[${emp.dept.name}]]</td>
                        <td>[[${emp.position.name}]]</td>

                        <td>
                            <a class="btn btn-outline-warning " th:href="@{/emp/}+${emp.id}" >
                                编辑
                            </a>
                            <button class="btn btn-outline-danger deleteBtn" th:attr="del_uri=@{/emp/}+${emp.id}">
                                删除
                            </button>

                        </td>
                    </tr>
                    </tbody>
                </table>

                <p class="info">
                <div class="d-flex flex-row bd-highlight mb-3">
                    <div class="p-2 bd-highlight">第[[${pageInfo.pageNum}]]页</div>
                    <div class="p-2 bd-highlight">共[[${pageInfo.pages}]]页</div>
                    <div class="p-2 bd-highlight">共[[${pageInfo.total}]]条记录</div>
                </div>
                <!-- 当前第 <span th:text="${pageInfo.pageNum}"></span> 页,总共 <span
                     th:text="${pageInfo.pages}"></span> 页,共 <span
                     th:text="${pageInfo.total}"></span> 条记录-->
                </p>
                <ul class="pagination">
                    <li class="page-item"><a class="page-link" th:href="@{/emps}">首页</a></li>
                    <li class="page-item"><a class="page-link"
                                             th:href="@{/emps(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a>
                    </li>
                    <li class="page-item"><a class="page-link"
                                             th:href="@{/emps(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a>
                    </li>
                    <li class="page-item"><a class="page-link" th:href="@{/emps(pageNum=${pageInfo.pages})}">尾页</a></li>
                </ul>
            </div>
        </main>
        <form id="deleteEmpForm" method="post">
            <input type="hidden" name="_method" value="delete"/>
        </form>
    </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript" th:src="@{/webjars/jquery/3.5.0/jquery.js}"></script>
<script type="text/javascript" th:src="@{/webjars/popper.js/1.14.3/popper.js}"></script>
<script type="text/javascript" th:src="@{/webjars/bootstrap/4.4.1-1/js/bootstrap.js}"></script>

<script type="text/javascript" th:src="@{/asserts/js/bootstrap-paginator.js}"></script>
<!-- Icons -->

<script>
    $(".deleteBtn").click(function () {
        //删除当前员工的
        $("#deleteEmpForm").attr("action", $(this).attr("del_uri")).submit();
        return false;
    });
</script>
</body>
</html>